/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisgeroupas.view;

import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import sisgeroupas.dao.ClienteDao;
import sisgeroupas.model.ModelCliente;
import sisgeroupas.model.TableModelCliente;

/**
 *
 * @author Frederico Ribeiro
 */
public class FrmIntCliente extends javax.swing.JInternalFrame {
    ModelCliente cliente2 = new ModelCliente();
    TableModelCliente modelo = new TableModelCliente();
    /**
     * Creates new form FrmIntCliente
     * 
     */
    
    static boolean clienteAlterado = false;//Variavel usada para marcar se o botao alterar foi pressionado
    public FrmIntCliente() {
        
        initComponents();
        //this.setSize(600,400);
        lblId.setVisible(false);
        //Criando a jTable cliente na aba Buscar
        modelo = new TableModelCliente();
        tblCliente.setModel(modelo);//Esse modelo que passo como parâmetro e feito em TableModelCliente.java no pacote model
        
        
        
        
        
        
        
        
    }
     
    
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tbpCliente = new javax.swing.JTabbedPane();
        pnlDadosCliente = new javax.swing.JPanel();
        txtNome = new javax.swing.JTextField();
        fmtDataNascimento = new javax.swing.JFormattedTextField();
        lblDataNascimento = new javax.swing.JLabel();
        lblNome = new javax.swing.JLabel();
        lblSexo = new javax.swing.JLabel();
        cmbSexo = new javax.swing.JComboBox();
        txtNomeMae = new javax.swing.JTextField();
        lblNomeMae = new javax.swing.JLabel();
        lblCpf = new javax.swing.JLabel();
        btnSalvar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        fmtCpf = new javax.swing.JFormattedTextField();
        pnlPrincipal = new javax.swing.JPanel();
        pnlEnderecamento = new javax.swing.JPanel();
        lblEstado = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lblRua = new javax.swing.JLabel();
        txtRua = new javax.swing.JTextField();
        txtNumero = new javax.swing.JTextField();
        lblNumero = new javax.swing.JLabel();
        lblComplemento = new javax.swing.JLabel();
        txtComplemento = new javax.swing.JTextField();
        lblBairro = new javax.swing.JLabel();
        txtBairro = new javax.swing.JTextField();
        txtEstado = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        lblId = new javax.swing.JLabel();
        pnlBuscar = new javax.swing.JPanel();
        txtBuscar = new javax.swing.JTextField();
        scpCliente = new javax.swing.JScrollPane();
        tblCliente = new javax.swing.JTable();
        btnBuscar = new javax.swing.JButton();
        btnSelecionar = new javax.swing.JButton();
        btnLimparBusca = new javax.swing.JButton();
        lblBuscar = new javax.swing.JLabel();

        setBorder(null);
        setClosable(true);
        setIconifiable(true);
        setTitle("Clientes");

        pnlDadosCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Dados Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        fmtDataNascimento.setColumns(10);
        try {
            fmtDataNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lblDataNascimento.setText("Data Nasc:");

        lblNome.setText("Nome:");

        lblSexo.setText("Sexo:");

        cmbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        lblNomeMae.setText("Nome Mãe:");

        lblCpf.setText("CPF:");

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/6228_32x32.png"))); // NOI18N
        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/7898_32x32.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/817_32x32.png"))); // NOI18N
        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/1957_32x32.png"))); // NOI18N
        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        fmtCpf.setColumns(15);
        try {
            fmtCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        pnlEnderecamento.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereçamento"));

        lblEstado.setText("Estado:");

        jLabel6.setText("Cidade:");

        lblRua.setText("Rua:");

        lblNumero.setText("Número:");

        lblComplemento.setText("Complemento:");

        lblBairro.setText("Bairro");

        javax.swing.GroupLayout pnlEnderecamentoLayout = new javax.swing.GroupLayout(pnlEnderecamento);
        pnlEnderecamento.setLayout(pnlEnderecamentoLayout);
        pnlEnderecamentoLayout.setHorizontalGroup(
            pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                        .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                                .addComponent(lblRua)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(txtRua))
                        .addGap(18, 18, 18)
                        .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNumero)
                            .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblComplemento)
                            .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                        .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                                .addComponent(lblEstado)
                                .addGap(115, 115, 115)
                                .addComponent(jLabel6))
                            .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                                .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtCidade)))
                        .addGap(18, 18, 18)
                        .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblBairro)
                            .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        pnlEnderecamentoLayout.setVerticalGroup(
            pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEnderecamentoLayout.createSequentialGroup()
                .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEstado)
                    .addComponent(jLabel6)
                    .addComponent(lblBairro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3)
                .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNumero)
                    .addComponent(lblComplemento)
                    .addComponent(lblRua))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlEnderecamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 17, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
        pnlPrincipal.setLayout(pnlPrincipalLayout);
        pnlPrincipalLayout.setHorizontalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlEnderecamento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlPrincipalLayout.setVerticalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addComponent(pnlEnderecamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout pnlDadosClienteLayout = new javax.swing.GroupLayout(pnlDadosCliente);
        pnlDadosCliente.setLayout(pnlDadosClienteLayout);
        pnlDadosClienteLayout.setHorizontalGroup(
            pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                        .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDataNascimento)
                            .addComponent(fmtDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                        .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSexo))
                        .addGap(31, 31, 31))
                    .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                        .addComponent(lblNome)
                        .addGap(102, 102, 102)
                        .addComponent(lblId)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                        .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                                .addComponent(lblNomeMae)
                                .addGap(272, 272, 272))
                            .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                                .addComponent(txtNomeMae)
                                .addGap(18, 18, 18)))
                        .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCpf)
                            .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                                .addComponent(fmtCpf)
                                .addGap(31, 31, 31))))))
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDadosClienteLayout.createSequentialGroup()
                .addComponent(btnLimpar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnAlterar)
                .addGap(56, 56, 56)
                .addComponent(btnExcluir)
                .addGap(39, 39, 39)
                .addComponent(btnSalvar)
                .addContainerGap())
        );
        pnlDadosClienteLayout.setVerticalGroup(
            pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosClienteLayout.createSequentialGroup()
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNome)
                    .addComponent(lblDataNascimento)
                    .addComponent(lblSexo)
                    .addComponent(lblId))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fmtDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNomeMae)
                    .addComponent(lblCpf))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNomeMae, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fmtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSalvar)
                    .addComponent(btnExcluir)
                    .addComponent(btnLimpar)
                    .addComponent(btnAlterar))
                .addContainerGap())
        );

        tbpCliente.addTab("Cliente", pnlDadosCliente);

        tblCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scpCliente.setViewportView(tblCliente);

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/lupa2_32x32.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnSelecionar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/check2_32x32.png"))); // NOI18N
        btnSelecionar.setText("Selecionar");
        btnSelecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelecionarActionPerformed(evt);
            }
        });

        btnLimparBusca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sisgeroupas/icones/817_32x32.png"))); // NOI18N
        btnLimparBusca.setText("Limpar");
        btnLimparBusca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparBuscaActionPerformed(evt);
            }
        });

        lblBuscar.setText("Buscar Cliente");

        javax.swing.GroupLayout pnlBuscarLayout = new javax.swing.GroupLayout(pnlBuscar);
        pnlBuscar.setLayout(pnlBuscarLayout);
        pnlBuscarLayout.setHorizontalGroup(
            pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblBuscar)
                        .addGroup(pnlBuscarLayout.createSequentialGroup()
                            .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(btnBuscar))
                        .addComponent(scpCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 517, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlBuscarLayout.createSequentialGroup()
                        .addComponent(btnSelecionar)
                        .addGap(32, 32, 32)
                        .addComponent(btnLimparBusca)))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        pnlBuscarLayout.setVerticalGroup(
            pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblBuscar)
                .addGap(2, 2, 2)
                .addGroup(pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscar))
                .addGap(18, 18, 18)
                .addComponent(scpCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(pnlBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSelecionar)
                    .addComponent(btnLimparBusca))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        tbpCliente.addTab("Buscar", pnlBuscar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tbpCliente)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tbpCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        tbpCliente.getAccessibleContext().setAccessibleDescription("Todas as informações sobre o Cliente");

        getAccessibleContext().setAccessibleName("Cliente - ");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnLimparBuscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparBuscaActionPerformed
        txtBuscar.setText("");
        modelo.limpar();
        
    }//GEN-LAST:event_btnLimparBuscaActionPerformed

    private void btnSelecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelecionarActionPerformed
        int linhaSel = tblCliente.getSelectedRow();
        int colunaSel = tblCliente.getSelectedColumn();

        ModelCliente cliente = modelo.getCliente(linhaSel);
        //JOptionPane.showMessageDialog(null,"Cadastro: " + cadastro.getNome());
        //modelo.getValueAt(int coluna, int linha);
        txtBuscar.setText("");
        modelo.limpar();

        lblId.setText(String.valueOf(cliente.getId()));//Coloca a valor do id em um label oculto

        txtNome.setText(cliente.getNome());
        fmtDataNascimento.setText(cliente.getDataNascimento());
        if(cliente.getSexo().equals("Feminino"))
        {
            cmbSexo.setSelectedItem("Feminino");
        }
        if(cliente.getSexo().equals("Masculino"))
        {
            cmbSexo.setSelectedItem("Masculino");
        }
        txtNomeMae.setText(cliente.getNomeMae());
        fmtCpf.setText(cliente.getCpf());
        txtEstado.setText(cliente.getEstado());
        txtCidade.setText(cliente.getCidade());
        txtBairro.setText(cliente.getBairro());
        txtRua.setText(cliente.getRua());
        txtNumero.setText(cliente.getNumero());
        txtComplemento.setText(cliente.getComplemento());
        
        tbpCliente.setSelectedIndex(0);//Muda o foco da aba
        desabilitaCampos();
    }//GEN-LAST:event_btnSelecionarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        ModelCliente cliente = new ModelCliente();

        cliente.setNome(txtBuscar.getText());

        ClienteDao dao = new ClienteDao();

        if(!dao.pesquisar(cliente).isEmpty()){//Verifica se a pesquisa vai retorna diferente de vazio
            ArrayList <ModelCliente> ResClientes =  dao.pesquisar(cliente);
            
            for(int i=0; i < ResClientes.size();i++)
            {
                
                modelo.addCadastro(ResClientes.get(i));
            }
        }else {
            JOptionPane.showMessageDialog(null,"Não foi encontrado nenhum resultado!");
        }
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        if(txtNome.getText().equals(""))
            JOptionPane.showMessageDialog(null,"O preenchimento do nome é obrigatorio!");
        /*else if((fmtDataNascimento.getText().equals("  /  /  ")))
            JOptionPane.showMessageDialog(null,"O preenchimento da Data de Nascimento é obrigatorio!");*/
        else if((txtNomeMae.getText().equals("")))
            JOptionPane.showMessageDialog(null,"O preenchimento do nome da Mãe é obrigatorio!");
        else{          
               if(clienteAlterado == true){//Atualiza
                     ModelCliente cliente = new ModelCliente();
                     cliente.setId(Integer.parseInt(lblId.getText()));
                    // System.out.println(cliente.getId());
                     cliente.setNome(txtNome.getText());
                     cliente.setDataNascimento(fmtDataNascimento.getText());
                     if(cmbSexo.getSelectedItem()== "Masculino")
                     {
                         cliente.setSexo("Masculino");
                     }
                     if(cmbSexo.getSelectedItem()== "Feminino")
                     {
                         cliente.setSexo("Feminino");
                     }
                     cliente.setNomeMae(txtNomeMae.getText());
                     cliente.setCpf(fmtCpf.getText());
                     cliente.setEstado(txtEstado.getText());
                     cliente.setCidade(txtCidade.getText());
                     cliente.setBairro(txtBairro.getText());
                     cliente.setRua(txtRua.getText());
                     cliente.setNumero(txtNumero.getText());
                     cliente.setComplemento(txtComplemento.getText());

                     ClienteDao dao = new ClienteDao();
                     dao.atualizar(cliente);
                     clienteAlterado = false;

                     JOptionPane.showMessageDialog(null,"Cliente alterado com Sucesso!");
                     desabilitaCampos();
                }
                else{//Salva
                        ModelCliente cliente = new ModelCliente();
                        cliente.setNome(txtNome.getText());
                        cliente.setDataNascimento(fmtDataNascimento.getText());
                        if(cmbSexo.getSelectedItem()== "Masculino")
                        {
                            cliente.setSexo("Masculino");
                        }
                        if(cmbSexo.getSelectedItem()== "Feminino")
                        {
                            cliente.setSexo("Feminino");
                        }
                        cliente.setNomeMae(txtNomeMae.getText());
                        cliente.setCpf(fmtCpf.getText());
                        cliente.setEstado(txtEstado.getText());
                        cliente.setCidade(txtCidade.getText());
                        cliente.setBairro(txtBairro.getText());
                        cliente.setRua(txtRua.getText());
                        cliente.setNumero(txtNumero.getText());
                        cliente.setComplemento(txtComplemento.getText());

                        ClienteDao clientedao = new ClienteDao();
                        clientedao.inserir(cliente);

                        JOptionPane.showMessageDialog(null,"Cliente Salvo com Sucesso!");
                    }
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
       limparCliente();
       habilitaCampos();
    }//GEN-LAST:event_btnLimparActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null,"Tem certeza que deseja deletar o cliente?");
        if(resposta == JOptionPane.YES_OPTION)
        {
        
            ModelCliente cliente = new ModelCliente();
             cliente.setId(Integer.parseInt(lblId.getText()));
             cliente.setNome(txtNome.getText());
             cliente.setDataNascimento(fmtDataNascimento.getText());
             if(cmbSexo.getSelectedItem()== "Masculino")
             {
                 cliente.setSexo("Masculino");
             }
             if(cmbSexo.getSelectedItem()== "Feminino")
             {
                 cliente.setSexo("Feminino");
             }
             cliente.setNomeMae(txtNomeMae.getText());
             cliente.setCpf(fmtCpf.getText());
             cliente.setEstado(txtEstado.getText());
             cliente.setCidade(txtCidade.getText());
             cliente.setBairro(txtBairro.getText());
             cliente.setRua(txtRua.getText());
             cliente.setNumero(txtNumero.getText());
             cliente.setComplemento(txtComplemento.getText());
             
             ClienteDao dao = new ClienteDao();
             dao.apagar(cliente);
             JOptionPane.showMessageDialog(null,"Cliente apagado com Sucesso!");
             limparCliente();
             habilitaCampos();
             }
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        habilitaCampos();
        clienteAlterado = true;
        
           
    }//GEN-LAST:event_btnAlterarActionPerformed

    
    public void desabilitaCampos(){
        txtNome.setEnabled(false);
        fmtDataNascimento.setEnabled(false);
        cmbSexo.setEnabled(false);
        txtNomeMae.setEnabled(false);
        fmtCpf.setEnabled(false);
        txtEstado.setEnabled(false);
        txtCidade.setEnabled(false);
        txtBairro.setEnabled(false);
        txtRua.setEnabled(false);
        txtNumero.setEnabled(false);
        txtComplemento.setEnabled(false);
        
        
    }
    public void limparCliente(){
        txtNome.setText("");
       fmtDataNascimento.setText("");
       cmbSexo.setSelectedIndex(0);
       txtNomeMae.setText("");
       fmtCpf.setText("");
       txtEstado.setText("");
       txtCidade.setText("");
       txtBairro.setText("");
       txtRua.setText("");
       txtNumero.setText("");
       txtComplemento.setText("");
}
    
    public void habilitaCampos(){
        txtNome.setEnabled(true);
        fmtDataNascimento.setEnabled(true);
        cmbSexo.setEnabled(true);
        txtNomeMae.setEnabled(true);
        fmtCpf.setEnabled(true);
        txtEstado.setEnabled(true);
        txtCidade.setEnabled(true);
        txtBairro.setEnabled(true);
        txtRua.setEnabled(true);
        txtNumero.setEnabled(true);
        txtComplemento.setEnabled(true);
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnLimparBusca;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnSelecionar;
    private javax.swing.JComboBox cmbSexo;
    private javax.swing.JFormattedTextField fmtCpf;
    private javax.swing.JFormattedTextField fmtDataNascimento;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblBuscar;
    private javax.swing.JLabel lblComplemento;
    private javax.swing.JLabel lblCpf;
    private javax.swing.JLabel lblDataNascimento;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblId;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblNomeMae;
    private javax.swing.JLabel lblNumero;
    private javax.swing.JLabel lblRua;
    private javax.swing.JLabel lblSexo;
    private javax.swing.JPanel pnlBuscar;
    private javax.swing.JPanel pnlDadosCliente;
    private javax.swing.JPanel pnlEnderecamento;
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JScrollPane scpCliente;
    private javax.swing.JTable tblCliente;
    private javax.swing.JTabbedPane tbpCliente;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtComplemento;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtNomeMae;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtRua;
    // End of variables declaration//GEN-END:variables



    public void setPosicao() {  
            Dimension d = this.getDesktopPane().getSize();  
            this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2); }  
    
        
}